Skip to content

Conversation

@jessica-oraegbu
Copy link

@jessica-oraegbu jessica-oraegbu commented Oct 21, 2025

Added section for Floating Point Precision on Writing and Reading to CSV Files to address issue #13159 with detailed explanation of why the precision loss happens as well as a code example demonstrating the solution.

df1.to_csv('test.csv', float_format='%.17g')
df2 = pd.read_csv('test.csv', index_col=0, float_precision='round_trip')
x1 = df1['One'][0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x1 = df1['One'][0]
x1 = df1.iloc[0, 0]

x1 = df1['One'][0]
x2 = df2['One'][0]
print("x0 = %f; x1 = %f; Are they equal? %s" % (x0, x1, (x0 == x1)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("x0 = %f; x1 = %f; Are they equal? %s" % (x0, x1, (x0 == x1)))
print(f"x0 = {x0}; x1 = {x1}; Are they equal? {x0 == x1}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC: floating point precision on writing/reading to csv

2 participants